package com.irdstudio.efp.report.service.impl;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.basic.framework.core.constant.SDicToExternalConstant;
import com.irdstudio.basic.framework.core.util.sdic.SDicToExternal;
import com.irdstudio.efp.report.service.dao.ZxbsCusIndivDao;
import com.irdstudio.efp.report.service.domain.ZxbsCusIndiv;
import com.irdstudio.efp.report.service.facade.ZxbsCusIndivService;
import com.irdstudio.efp.report.service.vo.ZxbsCusIndivVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Service Impl: 个人客户信息表服务实现
 *
 * @author gcb
 * @date 2020-11-02
 */
@Service("zxbsCusIndivService")
public class ZxbsCusIndivServiceImpl implements ZxbsCusIndivService, FrameworkService {

    private static Logger logger = LoggerFactory.getLogger(ZxbsCusIndivServiceImpl.class);

    @Autowired
    private ZxbsCusIndivDao zxbsCusIndivDao;

    /**
     * 新增数据
     *
     * @param zxbsCusIndivVo
     * @return
     */
    @Override
    public int insert(ZxbsCusIndivVO zxbsCusIndivVo) throws Exception {
        ZxbsCusIndiv zxbsCusIndiv = new ZxbsCusIndiv();
        beanCopy(zxbsCusIndivVo, zxbsCusIndiv);
        return zxbsCusIndivDao.insert(zxbsCusIndiv);
    }

    /**
     * 根据主键删除信息
     *
     * @param zxbsCusIndivVo
     * @return
     */
    @Override
    public int deleteByPk(ZxbsCusIndivVO zxbsCusIndivVo) throws Exception {
        ZxbsCusIndiv zxbsCusIndiv = new ZxbsCusIndiv();
        beanCopy(zxbsCusIndivVo, zxbsCusIndiv);
        return zxbsCusIndivDao.deleteByPk(zxbsCusIndiv);
    }

    /**
     * 根据主键更新信息
     *
     * @param zxbsCusIndivVo
     * @return
     */
    @Override
    public int updateByPk(ZxbsCusIndivVO zxbsCusIndivVo) throws Exception {
        ZxbsCusIndiv zxbsCusIndiv = new ZxbsCusIndiv();
        beanCopy(zxbsCusIndivVo, zxbsCusIndiv);
        return zxbsCusIndivDao.updateByPk(zxbsCusIndiv);
    }

    /**
     * 根据主键查询详情
     *
     * @param inZxbsCusIndivVo
     * @return
     */
    @Override
    public ZxbsCusIndivVO queryByPk(ZxbsCusIndivVO inZxbsCusIndivVo) throws Exception {
        ZxbsCusIndiv queryZxbsCusIndiv = new ZxbsCusIndiv();
        beanCopy(inZxbsCusIndivVo, queryZxbsCusIndiv);
        ZxbsCusIndiv queryRslZxbsCusIndiv = zxbsCusIndivDao.queryByPk(queryZxbsCusIndiv);
        return beanCopy(queryRslZxbsCusIndiv, new ZxbsCusIndivVO());
    }

    @Override
    public boolean updateCusIndiv() throws Exception{
        List<ZxbsCusIndivVO> cusIndivList = queryByCond();
        if (cusIndivList != null && cusIndivList.size()>0){
            for (ZxbsCusIndivVO vo :cusIndivList){
                vo.setIndivOcc(SDicToExternal.getExternalSysDicVal(SDicToExternalConstant.SYSID_IFP, SDicToExternalConstant.CRR, vo.getIndivOcc()));
                updateByPk(vo);
            }
        }


        return false;
    }

    @Override
    public List<ZxbsCusIndivVO> queryByCond() throws Exception{

        return (List<ZxbsCusIndivVO>)beansCopy(zxbsCusIndivDao.queryByCond(),ZxbsCusIndivVO.class);
    }
}
